﻿public partial class Solution
{
    /// <summary>
    /// 二分查找
    /// </summary>
    /// <param name="nums"></param>
    /// <param name="target"></param>
    /// <returns></returns>
    public int Search(int[] nums, int target)
    {
        int lp = 0;
        int rp = nums.Length - 1;
        int result = -1;
        while (lp <= rp)
        {
            int mp = (lp + rp) / 2;
            if (nums[mp] == target)
            {
                result = mp;
                break;
            }
            else
            if (nums[mp] < target)
            {
                lp = mp + 1;
            }
            else
            {
                rp = mp - 1;
            }
        }
        return result;
    }
}